home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / benchmarks / stat / stat.c < prev   
Encoding:
C/C++ Source or Header  |  1989-09-14  |  2.1 KB  |  77 lines

  1. /* 
  2.  * stat.c --
  3.  *
  4.  *    This program is a stand-alone benchmark that measures
  5.  *    the cost of stat-ing a file.
  6.  *
  7.  *    stat fileName count
  8.  *
  9.  *    where "fileName" is the name of the file to stat and
  10.  *    close and "count" tells how many stats to execute.
  11.  *
  12.  * Copyright 1989 Regents of the University of California.
  13.  * Permission to use, copy, modify, and distribute this
  14.  * software and its documentation for any purpose and without
  15.  * fee is hereby granted, provided that the above copyright
  16.  * notice appear in all copies.  The University of California
  17.  * makes no representations about the suitability of this
  18.  * software for any purpose.  It is provided "as is" without
  19.  * express or implied warranty.
  20.  */
  21.  
  22. #ifndef lint
  23. static char rcsid[] = "$Header: /sprite/src/benchmarks/stat/RCS/stat.c,v 1.1 89/09/13 20:49:03 ouster Exp $ SPRITE (Berkeley)";
  24. #endif not lint
  25.  
  26.  
  27. #include <stdio.h>
  28. #include <sys/types.h>
  29. #include <sys/stat.h>
  30. #include <sys/time.h>
  31. #include <sys/resource.h>
  32.  
  33. main(argc, argv)
  34. int argc;
  35. char **argv;
  36. {
  37.     struct stat buf;
  38.     int repeats, fd, count;
  39.     double msPer, micros;
  40.     struct rusage begin ,end;
  41.     struct timeval start, stop;
  42.     struct timezone tz;
  43.  
  44.     if (argc != 3) {
  45.     fprintf(stderr, "Usage:  %s fileName count\n",
  46.         argv[0]);
  47.     exit(1);
  48.     }
  49.     repeats = atoi(argv[2]);
  50.  
  51. #ifdef GETRUSAGE
  52.     getrusage(RUSAGE_SELF, &begin);
  53. #else
  54.     gettimeofday(&start, (struct timezone *) NULL);
  55. #endif
  56.  
  57.     for (count = 0 ; count < repeats; count++) {
  58.     if (stat(argv[1], &buf) != 0) {
  59.         fprintf(stderr, "Couldn't stat %s.\n", argv[1]);
  60.         exit(1);
  61.     }
  62.     }
  63. #ifdef GETRUSAGE
  64.     getrusage(RUSAGE_SELF, &end);
  65.     micros = (end.ru_utime.tv_sec + end.ru_stime.tv_sec
  66.         - begin.ru_utime.tv_sec - begin.ru_stime.tv_sec)*1000000
  67.         + (end.ru_utime.tv_usec - begin.ru_utime.tv_usec)
  68.         + (end.ru_stime.tv_usec - begin.ru_stime.tv_usec);
  69. #else
  70.     gettimeofday(&stop, (struct timezone *) NULL);
  71.     micros = 1000000*(stop.tv_sec - start.tv_sec)
  72.         + stop.tv_usec - start.tv_usec;
  73. #endif
  74.     msPer = (micros/repeats/1000.0);
  75.     printf("Time per stat: %.2f milliseconds\n", msPer);
  76. }
  77.